home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <stdio.h>
- #include "WeekOverview.h"
- #include "VCal.h"
- #include "Preferences.h"
- #include "TimeWeekdayEntry.h"
- #include "Info.h"
- #include "DayView.h"
- #include <Vk/VkMenuBar.h>
- #include <Vk/VkMenuItem.h>
- #include <Vk/VkHelpPane.h>
-
- #include <Xm/Form.h>
- #include <Xm/DrawingA.h>
- #include <Xm/Label.h>
- #include <Xm/LabelG.h>
- #include <Xm/ToggleBG.h>
-
- static int count;
- static Arg args[10];
-
- /**********************************************************************/
-
- WeekOverview::WeekOverview(VCal *o, const char *docName)
- : VkWindow(docName)
- {
- owner = o;
-
- day = month = year = 0;
- grid = NULL;
- restricted = thePreferences->restricted();
- timeInterval = thePreferences->gridLength();
- subdivisions = thePreferences->apptSubdiv();
- timeSlotSnap = thePreferences->snapInterval();
- restricted = thePreferences->restricted();
- restrictStart = 60*thePreferences->restrictStart();
- restrictEnd = 60*thePreferences->restrictStop();
- defaultLength = thePreferences->apptLength();
- numEntries = 0;
- sizeEntries = 16;
- entries = (TimeWeekdayEntry **)
- malloc(sizeEntries*sizeof(TimeWeekdayEntry *));
- dirty = False;
- troughGC = NULL;
- headerArea = NULL;
- }
-
- WeekOverview::~WeekOverview()
- {
- clearData();
- free(entries);
- if (troughGC) {
- XtReleaseGC(form, troughGC);
- }
- if (headerArea) {
- XtAddCallback(headerArea, XmNexposeCallback,
- WeekOverview::expose_check, (XtPointer) this);
- }
- }
-
- const char *
- WeekOverview::className()
- {
- return "WeekOverview";
- }
-
- /**********************************************************************/
-
- void
- WeekOverview::selectWeek(int d, int m, int y)
- {
- int weekday, each;
- char str[256];
- XmString xs;
-
- day = d;
- month = m;
- year = y;
- if (visible() && !iconic()) {
- if (owner->getDayView() &&
- owner->getDayView()->visible()) {
- weekday = computeWeekday(owner->getDayView()->day(),
- owner->getDayView()->month(),
- owner->getDayView()->year());
- highlightWeekday(weekday);
- } else {
- highlightWeekday(0);
- }
- weekday = computeWeekday(d, m, y);
- decrementDate(d, m, y, weekday-1, &day, &month, &year);
- clearData();
- for (each=0; each<DAYS_IN_WEEK; each++) {
- augmentDate(day, month, year, each, &d, &m, &y);
- addDateEntries(d, m, y, each+1);
- }
- scroll->reannotateScrollBar();
-
- strcpy(str, "Week of ");
- formatDate(day, month, year, str+strlen(str));
- strcat(str, " to ");
- augmentDate(day, month, year, DAYS_IN_WEEK-1, &d, &m, &y);
- formatDate(d, m, y, str+strlen(str));
- xs = XmStringCreateSimple(str);
- count = 0;
- XtSetArg(args[count], XmNlabelString, xs); count++;
- XtSetValues(weekLabel, args, count);
- XmStringFree(xs);
-
- dirty = False;
- } else {
- dirty = True;
- }
- }
-
- /**********************************************************************/
-
- Widget
- WeekOverview::setUpInterface(Widget parent)
- {
- int each;
- XmString xs;
- char name[256];
-
- fileMenu();
- if (menu()->helpPane()) {
- menu()->helpPane()->setItemSensitivities(False, True, False, False,
- False);
- }
-
- count = 0;
- form = XmCreateForm(parent, "weekOverviewForm", args, count);
-
- scroll = new VkScroll("scroll", form);
- VkAddCallbackMethod(VkScroll::scrollCallback, scroll, this,
- WeekOverview::scrollProc, NULL);
- scroll->setAnnotations();
-
- count = 0;
- XtSetArg(args[count], XmNtopAttachment, XmATTACH_FORM); count++;
- XtSetArg(args[count], XmNleftAttachment, XmATTACH_FORM); count++;
- XtSetArg(args[count], XmNrightAttachment, XmATTACH_FORM); count++;
- weekLabel = XmCreateLabelGadget(form, "weekLabel", args, count);
- XtManageChild(weekLabel);
-
- count = 0;
- XtSetArg(args[count], XmNtopAttachment, XmATTACH_WIDGET); count++;
- XtSetArg(args[count], XmNtopWidget, weekLabel); count++;
- XtSetArg(args[count], XmNleftAttachment, XmATTACH_FORM); count++;
- XtSetArg(args[count], XmNrightAttachment, XmATTACH_FORM); count++;
- XtSetArg(args[count], XmNbackground, owner->normalColor()); count++;
- headerArea = XmCreateDrawingArea(form, "headerArea", args, count);
- XtManageChild(headerArea);
- XtAddCallback(headerArea, XmNexposeCallback,
- WeekOverview::expose_check, (XtPointer) this);
-
- for (each=0; each<DAYS_IN_WEEK; each++) {
- sprintf(name, "%s", weekdayString(each+1));
- xs = XmStringCreateSimple(name);
- count = 0;
- XtSetArg(args[count], XmNlabelString, xs); count++;
- headerLabels[each] = XmCreateLabel(headerArea, "headerLabel", args, count);
- XmStringFree(xs);
- XtManageChild(headerLabels[each]);
- }
-
- count = 0;
- XtSetArg(args[count], XmNtopAttachment, XmATTACH_WIDGET); count++;
- XtSetArg(args[count], XmNtopWidget, headerArea); count++;
- XtSetArg(args[count], XmNleftAttachment, XmATTACH_FORM); count++;
- XtSetArg(args[count], XmNrightAttachment, XmATTACH_FORM); count++;
- XtSetArg(args[count], XmNbottomAttachment, XmATTACH_FORM); count++;
- XtSetValues(scroll->baseWidget(), args, count);
-
- if (restricted) {
- grid = new TimeGrid("timeGrid", scroll->getClip(), False,
- timeInterval, subdivisions,
- restrictStart, restrictEnd-restrictStart);
- } else {
- grid = new TimeGrid("timeGrid", scroll->getClip(), False);
- }
- grid->setCallback(WeekOverview::grid_stub, (XtPointer) this);
- count = 0;
- XtSetArg(args[count], XmNtopAttachment, XmATTACH_NONE); count++;
- XtSetArg(args[count], XmNbottomAttachment, XmATTACH_NONE); count++;
- XtSetArg(args[count], XmNleftAttachment, XmATTACH_FORM); count++;
- XtSetArg(args[count], XmNrightAttachment, XmATTACH_FORM); count++;
- XtSetValues(grid->baseWidget(), args, count);
- scroll->setChild(grid->baseWidget());
- grid->show();
-
- XtManageChild(form);
- return form;
- }
-
- void
- WeekOverview::handleWmDeleteMessage()
- {
- doQuit();
- }
-
- void
- WeekOverview::fileMenu()
- {
- VkSubMenu* menu = addMenuPane("weekOverviewFileMenu");
- VkMenuToggle *item;
-
- item = menu->addToggle("restrictedToggleMenuItem",
- WeekOverview::restricted_menu,
- (XtPointer) this);
- item->setVisualState(thePreferences->restricted());
- menu->addSeparator();
- menu->addAction("weekOverviewQuitMenuItem",
- WeekOverview::quit_menu,
- (XtPointer) this);
- }
-
- void
- WeekOverview::doQuit()
- {
- hide();
- }
-
- void
- WeekOverview::restrictedChanged(Boolean r)
- {
- if (restricted != r) {
- theApplication->busy();
- restricted = r;
- if (restricted) {
- grid->changeDuration(restrictStart, restrictEnd-restrictStart);
- } else {
- grid->changeDuration(0, MINS_IN_DAY);
- }
- updateDisplay();
- scroll->recomputeScrollBar();
- theApplication->notBusy();
- }
- }
-
- void
- WeekOverview::scrollProc(Widget, XtPointer, XtPointer call_data)
- {
- VkScrollCallback *cb = (VkScrollCallback *) call_data;
-
- switch (cb->reason) {
- case VS_initialExpose:
- adjustGrid();
- break;
- case VS_resize:
- // Make the grid reconfigure first
- grid->reconfig();
- adjustGrid();
- updateDisplay();
- break;
- case VS_troughPixmap:
- drawTrough(cb);
- // Do nothing, no annotations in this view
- break;
- case VS_none:
- default:
- break;
- }
- }
-
- void
- WeekOverview::gridCallback(TimeGridCallback *cb)
- {
- int each, d, m, y;
- Position x;
- Dimension width, borderWidth;
- XEvent *event;
-
- switch (cb->reason) {
- case TG_requestNew:
- // Select a new day
- if ((event = (XEvent *) cb->data) &&
- event->type == ButtonPress) {
- for (each=0; each<DAYS_IN_WEEK; each++) {
- count = 0;
- XtSetArg(args[count], XmNx, &x); count++;
- XtSetArg(args[count], XmNwidth, &width); count++;
- XtSetArg(args[count], XmNborderWidth, &borderWidth); count++;
- XtGetValues(headerLabels[each], args, count);
- width += borderWidth;
- if (event->xbutton.x >= x &&
- event->xbutton.x < x+width) {
- augmentDate(day, month, year, each, &d, &m, &y);
- owner->selectDay(d, m, y);
- break;
- }
- }
- }
- break;
- case TG_deselect:
- // Do nothing, this view is non-editable
- break;
- case TG_none:
- break;
- }
- }
-
- void
- WeekOverview::adjustGrid()
- {
- int each;
- Position x, y;
- Dimension width, height, borderWidth;
-
- count = 0;
- XtSetArg(args[count], XmNincrement,
- grid->getSlotHeight()*grid->getSubDiv()); count++;
- XtSetValues(scroll->getScrollBar(), args, count);
- for (each=0; each<DAYS_IN_WEEK; each++) {
- if (grid->requestWeekdayPosition(restrictStart, 0, each+1,
- &x, &y, &width, &height)) {
- count = 0;
- XtSetArg(args[count], XmNborderWidth, &borderWidth); count++;
- XtGetValues(headerLabels[each], args, count);
- count = 0;
- XtSetArg(args[count], XmNx, x+borderWidth); count++;
- XtSetArg(args[count], XmNwidth, width-2*borderWidth); count++;
- XtSetValues(headerLabels[each], args, count);
- }
- }
- for (each=0; each<numEntries; each++) {
- if (entries[each]->reposition()) {
- entries[each]->show();
- } else {
- entries[each]->hide();
- }
- }
- }
-
- void
- WeekOverview::clearData()
- {
- int each;
-
- for (each=0; each<numEntries; each++) {
- delete entries[each];
- }
- numEntries = 0;
- }
-
- void
- WeekOverview::addDateEntries(int day, int month, int year, int weekday)
- {
- MemoryInfo *info;
- Entry *entry;
- RepeatingEntry *rentry;
-
- info = owner->findDateInfo(day, month, year);
- if (info) {
- info->rewind();
- while (entry = info->nextEntry()) {
- addEntry(entry, weekday);
- }
- }
- rentry = owner->getRepeatingEntries();
- while (rentry->next()) {
- rentry = rentry->next();
- if (rentry->repeatApplies(day, month, year)) {
- addEntry(rentry, weekday);
- }
- }
- }
-
- void
- WeekOverview::addEntry(Entry *entry, int weekday)
- {
- if (numEntries == sizeEntries) {
- sizeEntries = 2*sizeEntries;
- entries = (TimeWeekdayEntry **) realloc(entries,
- sizeEntries*sizeof(TimeWeekdayEntry *));
- }
- entries[numEntries] = new TimeWeekdayEntry("timeWeekdayEntry", grid,
- weekday);
- entries[numEntries]->setCallback(WeekOverview::entry_stub, (XtPointer) this);
- entries[numEntries]->setText(entry->text());
- if (entries[numEntries]->setTimeInterval(entry->start(),
- entry->length())) {
- entries[numEntries]->show();
- }
- numEntries++;
- }
-
- void
- WeekOverview::entryCallback(Widget, TimeEntryCallback *cb)
- {
- int time, d, m, y;
-
- if (cb->reason == TE_selected) {
- time = cb->obj->start();
- augmentDate(day, month, year, ((TimeWeekdayEntry *) cb->obj)->weekday()-1,
- &d, &m, &y);
- owner->selectDay(d, m, y);
- if (owner->getDayView()) {
- owner->getDayView()->scrollToTime(time);
- }
- }
- }
-
- void
- WeekOverview::drawTrough(VkScrollCallback *cb)
- {
- XGCValues gcv;
- Pixel fg;
- int each;
-
- if (troughGC == NULL) {
- count = 0;
- XtSetArg(args[count], XmNforeground, &fg); count++;
- XtGetValues(headerArea, args, count);
- gcv.function = GXcopy;
- gcv.foreground = fg;
- gcv.background = owner->annotateColor();
- gcv.stipple = owner->getTile();
- gcv.fill_style = FillOpaqueStippled;
- troughGC = XtGetGC(form,
- GCFunction | GCForeground | GCBackground |
- GCStipple | GCFillStyle,
- &gcv);
- }
-
- for (each=0; each<numEntries; each++) {
- if (XtIsManaged(entries[each]->baseWidget())) {
- annotateEntry(entries[each], cb->width, cb->height, cb->pixmap);
- }
- }
- }
-
- void
- WeekOverview::annotateEntry(TimeEntry *entry, int width, int height,
- Pixmap pixmap)
- {
- Position y;
- Dimension height2;
- int h;
-
- count = 0;
- XtSetArg(args[count], XmNy, &y); count++;
- XtSetArg(args[count], XmNheight, &height2); count++;
- XtGetValues(entry->baseWidget(), args, count);
- h = ((int) height2*height)/grid->getHeight();
- if (h > 3) {
- h -= 1;
- }
- XFillRectangle(XtDisplay(_baseWidget), pixmap, troughGC,
- 0, ((int) y*height)/grid->getHeight(),
- width, h);
- }
-
- void
- WeekOverview::highlightWeekday(int weekday)
- {
- int each;
-
- for (each=0; each<DAYS_IN_WEEK; each++) {
- count = 0;
- if (each == weekday-1) {
- XtSetArg(args[count], XmNborderColor, owner->foregroundColor()); count++;
- } else {
- XtSetArg(args[count], XmNborderColor, owner->normalColor()); count++;
- }
- XtSetValues(headerLabels[each], args, count);
- }
- }
-
- /************************************************************/
-
- void
- WeekOverview::quit_menu(Widget, XtPointer client_data, XtPointer)
- {
- WeekOverview *obj = (WeekOverview *) client_data;
-
- obj->doQuit();
- }
-
- void
- WeekOverview::restricted_menu(Widget w, XtPointer client_data, XtPointer)
- {
- WeekOverview *obj = (WeekOverview *) client_data;
-
- obj->restrictedChanged(XmToggleButtonGadgetGetState(w));
- }
-
- void
- WeekOverview::grid_stub(Widget, XtPointer client_data, XtPointer call_data)
- {
- WeekOverview *obj = (WeekOverview *) client_data;
- TimeGridCallback *cb = (TimeGridCallback *) call_data;
-
- obj->gridCallback(cb);
- }
-
- void
- WeekOverview::expose_check(Widget, XtPointer client_data, XtPointer)
- {
- WeekOverview *obj = (WeekOverview *) client_data;
-
- if (obj->dirty) {
- obj->updateDisplay();
- }
- }
-
- void
- WeekOverview::entry_stub(Widget w, XtPointer client_data, XtPointer call_data)
- {
- WeekOverview *obj = (WeekOverview *) client_data;
- TimeEntryCallback *cb = (TimeEntryCallback *) call_data;
-
- obj->entryCallback(w, cb);
- }
-
-